﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace APPLICATION.Departments
{
    public partial class frmEdit : Form
    {
        private string strHName;
        private int intMgrID, intCodeID;

        public frmEdit(string strParentName, string strName, int intMgr, int intCode)
        {
            InitializeComponent();
            
            strHName = strName;
            intMgrID = intMgr;
            intCodeID = intCode;

            txtParentName.Text = strParentName;
            txtName.Text = strHName;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlCommand cmdSQL = new System.Data.SqlClient.SqlCommand();
            cmdSQL.CommandText = "tsp_dtDep";
            cmdSQL.CommandType = CommandType.StoredProcedure;
            cmdSQL.Parameters.Add("@Action", SqlDbType.TinyInt).Value = 1;
            cmdSQL.Parameters.Add("@hName", SqlDbType.NVarChar, 50).Value = txtName.Text.Trim();
            cmdSQL.Parameters.Add("@mgrid", SqlDbType.Int).Value = intMgrID;
            cmdSQL.Parameters.Add("@CodeID", SqlDbType.Int).Value = intCodeID;

            System.Data.SqlClient.SqlConnection cnSQL = new System.Data.SqlClient.SqlConnection();
            cnSQL.ConnectionString = globals.APPCONNSTRING;

            try
            {
                cnSQL.Open();
                cmdSQL.Connection = cnSQL;
                cmdSQL.ExecuteNonQuery();
                cnSQL.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка во время сохранения! \n" + ex.Message, "TIMS");
                this.Close();
            }

        }
    }
}
